#include<iostream>
#include<vector>
using namespace std;


class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int left = 0; int right = 0;
        int len = nums.size();
        int numSum = 0;
        int digitCount = 0;
        int ansCount = INT_MAX;
        while (left < len) {
            if (numSum < target && right < len) {
                numSum += nums[right];
                right++;
                digitCount++;
            }
            else if (numSum >= target) {
                ansCount = min(ansCount, digitCount);
                numSum -= nums[left];
                left++;
                digitCount--;
            }
            else {
                break;
            }
        }
        return ansCount == INT_MAX ? 0 : ansCount;
    }
};